using System.Text.Json;
using Arcane.Source.Combat;
using Godot;

namespace Arcane.Source.Data;

public class RuneProto
{
    public string name;
    public string desc;
    public Element element;
    public Texture2D icon;
    public SpellProto spell;
    public SpellProto proSpell;

    public static RuneProto Create(RuneRes res)
    {
        var name = TranslationServer.Translate(res.Name);
        var desc = TranslationServer.Translate(res.Name + ".desc");
        var icon = res.Icon;

        var spell = GameDB.Spell.Get(res.SpellId);
        var proSpell = GameDB.Spell.Get(res.ProSpellId);

        return new()
        {
            name = name,
            desc = desc,
            icon = icon,
            element = res.Element,
            spell = spell,
            proSpell = proSpell,
        };
    }

    public Texture2D GetTexture(int level) => level switch
    {
        0 => icon,
        1 => spell.icon,
        2 => proSpell.icon,
        _ => null,
    };

    public void Cast(Entity entity, int level)
    {
        if (level == 1)
        {
            spell.Cast(entity);
        }
        else if (level == 2)
        {
            proSpell.Cast(entity);
        }
    }
}